package com.amap.search.listener;

import cn.hutool.core.bean.BeanUtil;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.amap.search.entity.db2022.PoiCode;
import com.amap.search.entity.excel.AdCodeExcel;
import com.amap.search.entity.excel.PoiCodeExcel;
import com.amap.search.mapper.db2022.PoiCodeMapper;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class PoiCodeExcelListener extends AnalysisEventListener<PoiCodeExcel> {
    private PoiCodeMapper poiCodeMapper;

    public PoiCodeExcelListener(PoiCodeMapper mapper){
        this.poiCodeMapper = mapper;
    }

    public PoiCodeExcelListener(){}

    @Override
    public void invoke(PoiCodeExcel excel, AnalysisContext analysisContext) {
        PoiCode poiCode = new PoiCode();
        BeanUtil.copyProperties(excel, poiCode);
        poiCodeMapper.insert(poiCode);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
        log.info("excel导入完毕");
    }
}
